package com.yunchang.springboot.scheduled.amazon.mws.report.datadispose;

import com.yunchang.springboot.models.mwsreportbean.MwsFeePreview;
import com.yunchang.springboot.models.mwsreportbean.MwsFeePreviewDO;
import com.yunchang.springboot.scheduled.amazon.mws.report.datadispose.parent.ReportDataDisposeParent;
import com.yunchang.springboot.scheduled.amazon.mws.report.datadispose.reportinterface.IReportDataDispose;
import com.yunchang.springboot.utils.DateUtil;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author czw
 * @date 2020/7/28 0028  18:47
 * @description:
 */
@Component
public class FeePreviewDataDispose extends ReportDataDisposeParent implements IReportDataDispose {
    /**
     * 费用预览 将获取到的数据转为实体对象数组
     *
     * @param lists
     * @param shopName
     * @param area
     */
    @Override
    public List<Object> reportDataDispose(List<List<String>> lists, String shopName, String area,String sellerId) {
        List<Object> insertList = new ArrayList<>(lists.size());
        List<String> titleList = lists.get(0);
        Map<String, Object> titleMap = new HashMap<>(titleList.size());
        for (int i = 0; i < titleList.size(); i++) {
            titleMap.put(titleList.get(i), i);
        }
        int skuIndex = Integer.valueOf(String.valueOf(titleMap.get("sku")));
        int fnSkuIndex = Integer.valueOf(String.valueOf(titleMap.get("fnsku")));
        int asinIndex = Integer.valueOf(String.valueOf(titleMap.get("asin")));
        int productNameIndex = Integer.valueOf(String.valueOf(titleMap.get("product-name")));
        int productGroupIndex = Integer.valueOf(String.valueOf(titleMap.get("product-group")));
        int brandIndex = Integer.valueOf(String.valueOf(titleMap.get("brand")));
        int fulfilledByIndex = Integer.valueOf(String.valueOf(titleMap.get("fulfilled-by")));
        int yourPriceIndex = Integer.valueOf(String.valueOf(titleMap.get("your-price")));
        int salesPriceIndex = Integer.valueOf(String.valueOf(titleMap.get("sales-price")));
        int longestSideIndex = Integer.valueOf(String.valueOf(titleMap.get("longest-side")));
        int medianSideIndex = Integer.valueOf(String.valueOf(titleMap.get("median-side")));
        int shortestSideIndex = Integer.valueOf(String.valueOf(titleMap.get("shortest-side")));
        int lengthAndGirthIndex = Integer.valueOf(String.valueOf(titleMap.get("length-and-girth")));
        int unitOfDimensionIndex = Integer.valueOf(String.valueOf(titleMap.get("unit-of-dimension")));
        int itemPackageWeightIndex = Integer.valueOf(String.valueOf(titleMap.get("item-package-weight")));
        int unitOfWeightIndex = Integer.valueOf(String.valueOf(titleMap.get("unit-of-weight")));
        int currencyIndex = Integer.valueOf(String.valueOf(titleMap.get("currency")));
        int estimatedFeeTotalIndex = Integer.valueOf(String.valueOf(titleMap.get("estimated-fee-total")));
        int estimatedReferralFeePerUnitIndex = Integer.valueOf(String.valueOf(titleMap.get("estimated-referral-fee-per-unit")));
        int estimatedVariableClosingFeeIndex = WRONG_NUMBER_SIGN;
        if (null != titleMap.get("estimated-variable-closing-fee")) {
            estimatedVariableClosingFeeIndex = Integer.valueOf(String.valueOf(titleMap.get("estimated-variable-closing-fee")));
        }
        int estimatedPickPackFeePerUnitIndex = WRONG_NUMBER_SIGN;
        if (null != titleMap.get("estimated-pick-pack-fee-per-unit")) {
            estimatedPickPackFeePerUnitIndex = Integer.valueOf(String.valueOf(titleMap.get("estimated-pick-pack-fee-per-unit")));
        }
        int estimatedWeightHandlingFeePerUnitIndex = WRONG_NUMBER_SIGN;
        if (null != titleMap.get("estimated-weight-handling-fee-per-unit")) {
            estimatedWeightHandlingFeePerUnitIndex = Integer.valueOf(String.valueOf(titleMap.get("estimated-weight-handling-fee-per-unit")));
        }
        int expectedFulfillmentFeePerUnitIndex = WRONG_NUMBER_SIGN;
        if (null != titleMap.get("expected-fulfillment-fee-per-unit")) {
            expectedFulfillmentFeePerUnitIndex = Integer.valueOf(String.valueOf(titleMap.get("expected-fulfillment-fee-per-unit")));
        }
        int hasLocalInventoryIndex = WRONG_NUMBER_SIGN;
        if (null != titleMap.get("has-local-inventory")) {
            hasLocalInventoryIndex = Integer.valueOf(String.valueOf(titleMap.get("has-local-inventory")));
        }
        int productSizeWeightBandIndex = WRONG_NUMBER_SIGN;
        if (null != titleMap.get("product-size-weight-band")) {
            productSizeWeightBandIndex = Integer.valueOf(String.valueOf(titleMap.get("product-size-weight-band")));
        }
        int estimatedOrderHandlingFeePerOrderIndex = WRONG_NUMBER_SIGN;
        if (null != titleMap.get("estimated-order-handling-fee-per-order")) {
            estimatedOrderHandlingFeePerOrderIndex = Integer.valueOf(String.valueOf(titleMap.get("estimated-order-handling-fee-per-order")));
        }
        int expectedDomesticFulfilmentFeePerUnitIndex = WRONG_NUMBER_SIGN;
        if (null != titleMap.get("expected-domestic-fulfilment-fee-per-unit")) {
            expectedDomesticFulfilmentFeePerUnitIndex = Integer.valueOf(String.valueOf(titleMap.get("expected-domestic-fulfilment-fee-per-unit")));
        }
        int expectedEfnFulfilmentFeePerUnitUkIndex = WRONG_NUMBER_SIGN;
        if (null != titleMap.get("expected-efn-fulfilment-fee-per-unit-uk")) {
            expectedEfnFulfilmentFeePerUnitUkIndex = Integer.valueOf(String.valueOf(titleMap.get("expected-efn-fulfilment-fee-per-unit-uk")));
        }
        int expectedEfnFulfilmentFeePerUnitDeIndex = WRONG_NUMBER_SIGN;
        if (null != titleMap.get("expected-efn-fulfilment-fee-per-unit-de")) {
            expectedEfnFulfilmentFeePerUnitDeIndex = Integer.valueOf(String.valueOf(titleMap.get("expected-efn-fulfilment-fee-per-unit-de")));
        }
        int expectedEfnFulfilmentFeePerUnitFrIndex = WRONG_NUMBER_SIGN;
        if (null != titleMap.get("expected-efn-fulfilment-fee-per-unit-fr")) {
            expectedEfnFulfilmentFeePerUnitFrIndex = Integer.valueOf(String.valueOf(titleMap.get("expected-efn-fulfilment-fee-per-unit-fr")));
        }
        int expectedEfnFulfilmentFeePerUnitItIndex = WRONG_NUMBER_SIGN;
        if (null != titleMap.get("expected-efn-fulfilment-fee-per-unit-it")) {
            expectedEfnFulfilmentFeePerUnitItIndex = Integer.valueOf(String.valueOf(titleMap.get("expected-efn-fulfilment-fee-per-unit-it")));
        }
        int expectedEfnFulfilmentFeePerUnitEsIndex = WRONG_NUMBER_SIGN;
        if (null != titleMap.get("expected-efn-fulfilment-fee-per-unit-es")) {
            expectedEfnFulfilmentFeePerUnitEsIndex = Integer.valueOf(String.valueOf(titleMap.get("expected-efn-fulfilment-fee-per-unit-es")));
        }
        int expectedFutureFulfilmentFeePrtUnitUkIndex = WRONG_NUMBER_SIGN;
        if (null != titleMap.get("expected-future-fulfilment-fee-prt-unit-uk")) {
            expectedFutureFulfilmentFeePrtUnitUkIndex = Integer.valueOf(String.valueOf(titleMap.get("expected-future-fulfilment-fee-prt-unit-uk")));
        }
        int expectedFutureFulfilmentFeePrtUnitDeIndex = WRONG_NUMBER_SIGN;
        if (null != titleMap.get("expected-future-fulfilment-fee-prt-unit-de")) {
            expectedFutureFulfilmentFeePrtUnitDeIndex = Integer.valueOf(String.valueOf(titleMap.get("expected-future-fulfilment-fee-prt-unit-de")));
        }
        int expectedFutureFulfilmentFeePrtUnitFrIndex = WRONG_NUMBER_SIGN;
        if (null != titleMap.get("expected-future-fulfilment-fee-prt-unit-fr")) {
            expectedFutureFulfilmentFeePrtUnitFrIndex = Integer.valueOf(String.valueOf(titleMap.get("expected-future-fulfilment-fee-prt-unit-fr")));
        }
        int expectedFutureFulfilmentFeePrtUnitItIndex = WRONG_NUMBER_SIGN;
        if (null != titleMap.get("expected-future-fulfilment-fee-prt-unit-it")) {
            expectedFutureFulfilmentFeePrtUnitItIndex = Integer.valueOf(String.valueOf(titleMap.get("expected-future-fulfilment-fee-prt-unit-it")));
        }
        int expectedFutureFulfilmentFeePrtUnitEsIndex = WRONG_NUMBER_SIGN;
        if (null != titleMap.get("expected-future-fulfilment-fee-prt-unit-es")) {
            expectedFutureFulfilmentFeePrtUnitEsIndex = Integer.valueOf(String.valueOf(titleMap.get("expected-future-fulfilment-fee-prt-unit-es")));
        }
        int estimatedFutureDomesticFulfilmentFeePerUnitIndex = WRONG_NUMBER_SIGN;
        if (null != titleMap.get("estimated-future-domestic-fulfilment-fee-per-unit")) {
            estimatedFutureDomesticFulfilmentFeePerUnitIndex = Integer.valueOf(String.valueOf(titleMap.get("estimated-future-domestic-fulfilment-fee-per-unit")));
        }
        int estimatedFutureOrderHandlingFeePerOrderIndex = WRONG_NUMBER_SIGN;
        if (null != titleMap.get("estimated-future-order-handling-fee-per-order")) {
            estimatedFutureOrderHandlingFeePerOrderIndex = Integer.valueOf(String.valueOf(titleMap.get("estimated-future-order-handling-fee-per-order")));
        }
        int expectedFutureDomesticFulfilmentFeePerUnitIndex = WRONG_NUMBER_SIGN;
        if (null != titleMap.get("expected-future-domestic-fulfilment-fee-per-unit")) {
            expectedFutureDomesticFulfilmentFeePerUnitIndex = Integer.valueOf(String.valueOf(titleMap.get("expected-future-domestic-fulfilment-fee-per-unit")));
        }
        int estimatedFutureFeeIndex = WRONG_NUMBER_SIGN;
        if (null != titleMap.get("estimated-future-fee")) {
            estimatedFutureFeeIndex = Integer.valueOf(String.valueOf(titleMap.get("estimated-future-fee")));
        }
        for (int i = 1; i < lists.size(); i++) {
            MwsFeePreviewDO mwsFeePreview = new MwsFeePreviewDO();
            List<String> row = lists.get(i);
            mwsFeePreview.setSellerId(sellerId);
            mwsFeePreview.setArea(area);
            mwsFeePreview.setSku(row.get(skuIndex));
            mwsFeePreview.setFnsku(row.get(fnSkuIndex));
            mwsFeePreview.setAsin(row.get(asinIndex));
            mwsFeePreview.setProductName(row.get(productNameIndex));
            mwsFeePreview.setProductGroup(row.get(productGroupIndex));
            mwsFeePreview.setBrand(row.get(brandIndex));
            mwsFeePreview.setFulfilledBy(row.get(fulfilledByIndex));
            mwsFeePreview.setYourPrice(row.get(yourPriceIndex));
            mwsFeePreview.setSalesPrice(row.get(salesPriceIndex));
            mwsFeePreview.setLongestSide(row.get(longestSideIndex));
            mwsFeePreview.setMedianSide(row.get(medianSideIndex));
            mwsFeePreview.setShortestSide(row.get(shortestSideIndex));
            mwsFeePreview.setLengthAndGirth(row.get(lengthAndGirthIndex));
            mwsFeePreview.setUnitOfDimension(row.get(unitOfDimensionIndex));
            mwsFeePreview.setItemPackageWeight(row.get(itemPackageWeightIndex));
            mwsFeePreview.setUnitOfWeight(row.get(unitOfWeightIndex));
            mwsFeePreview.setCurrency(row.get(currencyIndex));
            mwsFeePreview.setEstimatedFeeTotal(row.get(estimatedFeeTotalIndex));
            mwsFeePreview.setEstimatedReferralFeePerUnit(row.get(estimatedReferralFeePerUnitIndex));
            mwsFeePreview.setCreateTime(DateUtil.getDate());
            mwsFeePreview.setUpdateTime(DateUtil.getDate());
            if (estimatedVariableClosingFeeIndex != WRONG_NUMBER_SIGN) {
                mwsFeePreview.setEstimatedVariableClosingFee(row.get(estimatedVariableClosingFeeIndex));
            }
            if (estimatedPickPackFeePerUnitIndex != WRONG_NUMBER_SIGN) {
                mwsFeePreview.setEstimatedPickPackFeePerUnit(row.get(estimatedPickPackFeePerUnitIndex));
            }
            if (estimatedWeightHandlingFeePerUnitIndex != WRONG_NUMBER_SIGN) {
                mwsFeePreview.setEstimatedWeightHandlingFeePerUnit(row.get(estimatedWeightHandlingFeePerUnitIndex));
            }
            if (expectedFulfillmentFeePerUnitIndex != WRONG_NUMBER_SIGN) {
                mwsFeePreview.setExpectedFulfillmentFeePerUnit(row.get(expectedFulfillmentFeePerUnitIndex));
            }
            mwsFeePreview.setCreateTime(DateUtil.getDate());
            if (hasLocalInventoryIndex != WRONG_NUMBER_SIGN) {
                mwsFeePreview.setHasLocalInventory(row.get(hasLocalInventoryIndex));
            }
            if (productSizeWeightBandIndex != WRONG_NUMBER_SIGN) {
                mwsFeePreview.setProductSizeWeightBand(row.get(productSizeWeightBandIndex));
            }
            if (estimatedOrderHandlingFeePerOrderIndex != WRONG_NUMBER_SIGN) {
                mwsFeePreview.setEstimatedOrderHandlingFeePerOrder(row.get(estimatedOrderHandlingFeePerOrderIndex));
            }
            if (expectedDomesticFulfilmentFeePerUnitIndex != WRONG_NUMBER_SIGN) {
                mwsFeePreview.setExpectedDomesticFulfilmentFeePerUnit(row.get(expectedDomesticFulfilmentFeePerUnitIndex));
            }
            if (expectedEfnFulfilmentFeePerUnitUkIndex != WRONG_NUMBER_SIGN) {
                mwsFeePreview.setExpectedEfnFulfilmentFeePerUnitUk(row.get(expectedEfnFulfilmentFeePerUnitUkIndex));
            }
            if (expectedEfnFulfilmentFeePerUnitDeIndex != WRONG_NUMBER_SIGN) {
                mwsFeePreview.setExpectedEfnFulfilmentFeePerUnitDe(row.get(expectedEfnFulfilmentFeePerUnitDeIndex));
            }
            if (expectedEfnFulfilmentFeePerUnitFrIndex != WRONG_NUMBER_SIGN) {
                mwsFeePreview.setExpectedEfnFulfilmentFeePerUnitFr(row.get(expectedEfnFulfilmentFeePerUnitFrIndex));
            }
            if (expectedEfnFulfilmentFeePerUnitItIndex != WRONG_NUMBER_SIGN) {
                mwsFeePreview.setExpectedEfnFulfilmentFeePerUnitIt(row.get(expectedEfnFulfilmentFeePerUnitItIndex));
            }
            if (expectedEfnFulfilmentFeePerUnitEsIndex != WRONG_NUMBER_SIGN) {
                mwsFeePreview.setExpectedEfnFulfilmentFeePerUnitEs(row.get(expectedEfnFulfilmentFeePerUnitEsIndex));
            }
            if (expectedFutureFulfilmentFeePrtUnitUkIndex != WRONG_NUMBER_SIGN) {
                mwsFeePreview.setExpectedFutureFulfilmentFeePrtUnitUk(row.get(expectedFutureFulfilmentFeePrtUnitUkIndex));
            }
            if (expectedFutureFulfilmentFeePrtUnitDeIndex != WRONG_NUMBER_SIGN) {
                mwsFeePreview.setExpectedFutureFulfilmentFeePrtUnitDe(row.get(expectedFutureFulfilmentFeePrtUnitDeIndex));
            }
            if (expectedFutureFulfilmentFeePrtUnitFrIndex != WRONG_NUMBER_SIGN) {
                mwsFeePreview.setExpectedFutureFulfilmentFeePrtUnitFr(row.get(expectedFutureFulfilmentFeePrtUnitFrIndex));
            }
            if (expectedFutureFulfilmentFeePrtUnitItIndex != WRONG_NUMBER_SIGN) {
                mwsFeePreview.setExpectedFutureFulfilmentFeePrtUnitIt(row.get(expectedFutureFulfilmentFeePrtUnitItIndex));
            }
            if (expectedFutureFulfilmentFeePrtUnitEsIndex != WRONG_NUMBER_SIGN) {
                mwsFeePreview.setExpectedFutureFulfilmentFeePrtUnitEs(row.get(expectedFutureFulfilmentFeePrtUnitEsIndex));
            }
            if (estimatedFutureDomesticFulfilmentFeePerUnitIndex != WRONG_NUMBER_SIGN) {
                mwsFeePreview.setEstimatedFutureDomesticFulfilmentFeePerUnit(row.get(estimatedFutureDomesticFulfilmentFeePerUnitIndex));
            }
            if (estimatedFutureOrderHandlingFeePerOrderIndex != WRONG_NUMBER_SIGN) {
                mwsFeePreview.setEstimatedFutureOrderHandlingFeePerOrder(row.get(estimatedFutureOrderHandlingFeePerOrderIndex));
            }
            if (expectedFutureDomesticFulfilmentFeePerUnitIndex != WRONG_NUMBER_SIGN) {
                mwsFeePreview.setExpectedFutureDomesticFulfilmentFeePerUnit(row.get(expectedFutureDomesticFulfilmentFeePerUnitIndex));
            }
            if (estimatedFutureFeeIndex != WRONG_NUMBER_SIGN) {
                mwsFeePreview.setEstimatedFutureFee(row.get(estimatedFutureFeeIndex));
            }
            mwsFeePreview.setFinanceStatus(1);
            insertList.add(mwsFeePreview);
        }
        return insertList;
    }
}
